import { Controller, Get, Post, Put, Body, Query, Param, Delete } from '@nestjs/common';
import { ApiTags, ApiOperation } from '@nestjs/swagger';
import { RequirePermission } from 'src/common/decorators/require-premission.decorator';
import { RecordsService } from './records.service';
import { CreateRecordsDto, BaseRecordsDto, UpdateRecordsDto, QueryRecordsDto, ListRecordsDto } from './dto/records.dto';
import { ApiDataResponse } from 'src/common/decorators/apiDataResponse.decorator';

@ApiTags('对话记录表，存储详细的对话内容和AI回复')
@Controller('system/records')
export class RecordsController {
  constructor(private readonly recordsService: RecordsService) {}

  @ApiOperation({ summary: '对话记录表，存储详细的对话内容和AI回复-创建' })
  @ApiDataResponse(BaseRecordsDto)
  // @RequirePermission('system:records:add')
  @Post()
  create(@Body() body: CreateRecordsDto) {
    return this.recordsService.create(body);
  }

  @ApiOperation({ summary: '对话记录表，存储详细的对话内容和AI回复-列表' })
  @ApiDataResponse(ListRecordsDto, true, true)
  // @RequirePermission('system:records:list')
  @Get('list')
  findAll(@Query() query: QueryRecordsDto) {
    return this.recordsService.findAll(query);
  }

  @ApiOperation({ summary: '对话记录表，存储详细的对话内容和AI回复-详情' })
  @ApiDataResponse(BaseRecordsDto)
  @RequirePermission('system:records:query')
  @Get(':id')
  findOne(@Param('id') id: number) {
    return this.recordsService.findOne(id);
  }

  @ApiOperation({ summary: '对话记录表，存储详细的对话内容和AI回复-修改' })
  @ApiDataResponse()
  @RequirePermission('system:records:edit')
  @Put()
  update(@Body() body: UpdateRecordsDto) {
    return this.recordsService.update(body);
  }

  @ApiOperation({ summary: '对话记录表，存储详细的对话内容和AI回复-删除' })
  @ApiDataResponse()
  @RequirePermission('system:records:remove')
  @Delete(':id')
  remove(@Param('id') id: string) {
    const ids = id.split(',').map((id) => +id);
    return this.recordsService.remove(ids);
  }

  @ApiOperation({ summary: '对话记录表，存储详细的对话内容和AI回复-获取' })
  @ApiDataResponse(ListRecordsDto, true, true)
  // @RequirePermission('system:records:query')
  @Get('context/:sessionId')
  findSessionContext(@Param('sessionId') sessionId: number) {
    return this.recordsService.findSessionContext(sessionId);
  }
}
